home *** CD-ROM | disk | FTP | other *** search
/ PC Player 2004 May / pc player 2004-05.iso / Demos / FarCry / Data1.cab / _E10101E45306418A9C95926C1FEE16D3 < prev    next >
Encoding:
Text File  |  2004-01-06  |  2.2 KB  |  109 lines

  1. -- AI_ConvManager - 
  2. -- Created by Petar; 10102002
  3. --------------------------
  4.  
  5.  
  6. AI_ConvManager = {
  7.  
  8.     NewConversation = {},
  9.     
  10. }
  11.  
  12. function AI_ConvManager:GetControlledRandomConv( conv_table )
  13.  
  14.     
  15.     local num_conv = count(conv_table);
  16.  
  17.     local rnd = random(1,num_conv);
  18.     
  19.  
  20.     local conv = conv_table[rnd];
  21.     local cnt = 0;
  22.     while (conv.UseTag) do
  23.         rnd=rnd+1;
  24.         if (rnd>num_conv) then
  25.             rnd = 1;
  26.         end
  27.         conv=conv_table[rnd];
  28.         cnt=cnt+1;
  29.  
  30.         -- reset conversation tags so they can be reused
  31.         if (cnt>num_conv) then 
  32.             for i,value in conv_table do
  33.                 value.UseTag=nil;
  34.             end
  35.         end
  36.     end
  37.  
  38.     conv.UseTag = 1;
  39.     return conv;
  40. end
  41.  
  42.  
  43. function AI_ConvManager:GetRandomIdleConversation()
  44.  
  45.     
  46.  
  47.     local conv = self:GetControlledRandomConv( AI_IdleConversations );
  48.     
  49.  
  50.     self.NewConversation = new(AI_Conversation);
  51.     self.NewConversation.Participants = conv.Participants;
  52.     self.NewConversation.ConversationScript = conv.Script;
  53.     self.NewConversation.ScriptLines = count(conv.Script);
  54.     self.NewConversation.Joined = 0;
  55.  
  56.     return self.NewConversation;
  57.     
  58. end
  59.  
  60. function AI_ConvManager:GetRandomCriticalConversation( name , inplace)
  61.  
  62.     local rnd;
  63.     local Conversation = AI_CriticalConversations[name];
  64.  
  65.     if (Conversation==nil) then
  66.         if (strlen(name) > 2) then 
  67.  
  68.         local short_name = strsub(name,1,strlen(name)-2);
  69.         Conversation = AI_CriticalConversations[short_name];
  70.         if (Conversation==nil) then
  71.                 System:Warning( "[AIWARNING] An agent requested a critical conversation ("..name..") that doesn't exist. Tried also ("..short_name..") that doesnt exist either.");
  72.             return nil;
  73.         end
  74.         
  75.         else
  76.  
  77.         System:Warning( "[AIWARNING] An agent requested a critical conversation ("..name..") that doesn't exist");
  78.         end
  79.  
  80.     end
  81.  
  82.     
  83.  
  84.     local RandomConv = self:GetControlledRandomConv( Conversation );
  85.  
  86.     self.NewConversation = new(AI_Conversation);
  87.     self.NewConversation.Participants = RandomConv.Participants;
  88.     self.NewConversation.Joined = 0;
  89.     self.NewConversation.ConversationScript = RandomConv.Script;
  90.     self.NewConversation.ScriptLines = count(RandomConv.Script);
  91.     if (inplace) then 
  92.         self.NewConversation.IN_PLACE = 1;
  93.     else
  94.         self.NewConversation.IN_PLACE = nil;
  95.     end
  96.  
  97.     return self.NewConversation;
  98. end
  99.  
  100.  
  101.  
  102.  
  103.  
  104.     
  105.                 
  106.     
  107.     
  108.     
  109.